package cn.bigfire.compiler.dragon.appendixA.handwrite.inter;

import cn.bigfire.compiler.dragon.appendixA.handwrite.lexer.Tag;
import cn.bigfire.compiler.dragon.appendixA.handwrite.lexer.Word;
import cn.bigfire.compiler.dragon.appendixA.handwrite.symbols.Type;

public class Access extends Op {

    public Id array;
    public Expr index;

    public Access(Id id, Expr expr, Type type) {
        super(new Word("[]", Tag.INDEX), type);
        array = id;
        index = expr;
    }

    public Expr gen(){
        return new Access(array, index.reduce(), type);
    }

    public void jumping(int t, int f) {
        emitJumps(reduce().toString(), t, f);
    }

    @Override
    public String toString() {
        return array.toString() + "[" + index.toString() + "]";
    }

}
